dnl Process this file with autoconf to produce a configure script.

AC_PREREQ(2.69)

dnl Initialization
AC_INIT([GNU Shepherd], [0.8.1], [bug-guix@gnu.org])
AC_CONFIG_SRCDIR([modules/shepherd.scm])
AC_CONFIG_AUX_DIR([build-aux])

dnl We're fine with GNU make constructs, hence '-Wno-portability'.
AM_INIT_AUTOMAKE([1.11 gnu silent-rules -Wall -Wno-portability
  std-options color-tests])

dnl Enable silent rules by default.
AM_SILENT_RULES([yes])

AM_GNU_GETTEXT([external])
AM_GNU_GETTEXT_VERSION([0.19])

AC_CANONICAL_HOST
AC_PROG_MKDIR_P
AC_PROG_SED

dnl Check for Guile 2.x+.
m4_pattern_forbid([^GUILE_PKG$])
GUILE_PKG([3.0 2.2 2.0])

dnl Checks for programs.
GUILE_PROGS

if test "x$GUILE_EFFECTIVE_VERSION" = "x2.0"; then
  PKG_CHECK_MODULES([GUILE], [guile-2.0 >= 2.0.13])
fi

guilemoduledir="${datarootdir}/guile/site/$GUILE_EFFECTIVE_VERSION"
guileobjectdir="${libdir}/guile/$GUILE_EFFECTIVE_VERSION/site-ccache"
AC_SUBST([guilemoduledir])
AC_SUBST([guileobjectdir])

dnl
dnl Low-level operating system interface.
dnl

AC_PROG_CC

dnl In practice that value is fixed for all platforms in glibc, but better
dnl check it.
AC_MSG_CHECKING([the '_SC_OPEN_MAX' value])
AC_COMPUTE_INT([_SC_OPEN_MAX], [_SC_OPEN_MAX], [#include <unistd.h>])
AC_MSG_RESULT([$_SC_OPEN_MAX])
AC_SUBST([_SC_OPEN_MAX])

AC_MSG_CHECKING([<sys/reboot.h> constants])
AC_COMPUTE_INT([RB_AUTOBOOT], [RB_AUTOBOOT], [#include <sys/reboot.h>])
case "$host_os" in
  linux-gnu*)
    AC_COMPUTE_INT([RB_HALT_SYSTEM], [RB_HALT_SYSTEM], [#include <sys/reboot.h>])
    AC_COMPUTE_INT([RB_ENABLE_CAD], [RB_ENABLE_CAD], [#include <sys/reboot.h>])
    AC_COMPUTE_INT([RB_DISABLE_CAD], [RB_DISABLE_CAD], [#include <sys/reboot.h>])
    AC_COMPUTE_INT([RB_POWER_OFF], [RB_POWER_OFF], [#include <sys/reboot.h>])
    AC_COMPUTE_INT([RB_SW_SUSPEND], [RB_SW_SUSPEND], [#include <sys/reboot.h>])
    ;;
  gnu*)
    # On GNU/Hurd, the Mach-derived reboot.h uses different names, and
    # has a different set of features and flags.
    AC_COMPUTE_INT([RB_HALT_SYSTEM], [RB_HALT], [#include <sys/reboot.h>])
    AC_COMPUTE_INT([RB_POWER_OFF], [RB_HALT], [#include <sys/reboot.h>])
    RB_DISABLE_CAD="#f"
    ;;
  *)
    # What is this?  GNU/kFreeBSD?
    AC_MSG_WARN([not sure how to halt the system on '$host_os'])
    AC_COMPUTE_INT([RB_HALT_SYSTEM], [RB_HALT_SYSTEM], [#include <sys/reboot.h>])
    AC_COMPUTE_INT([RB_POWER_OFF], [RB_HALT_SYSTEM], [#include <sys/reboot.h>])
    RB_DISABLE_CAD="#f"
    ;;
esac

AC_SUBST([RB_DISABLE_CAD])
AC_SUBST([RB_AUTOBOOT])
AC_SUBST([RB_HALT_SYSTEM])
AC_SUBST([RB_POWER_OFF])
AC_MSG_RESULT([done])

AC_MSG_CHECKING([<sys/prctl.h> constants])
AC_COMPUTE_INT([PR_SET_CHILD_SUBREAPER], [PR_SET_CHILD_SUBREAPER], [#include <sys/prctl.h>])
AC_SUBST([PR_SET_CHILD_SUBREAPER])
AC_MSG_RESULT([done])

dnl Check the size of 'signalfd_siginfo'.  If it's undefined, returns zero.
AC_CHECK_SIZEOF([struct signalfd_siginfo], [], [#include <sys/signalfd.h>])
AC_CHECK_SIZEOF([sigset_t], [], [#include <signal.h>])

AC_MSG_CHECKING([<sys/signalfd.h> and <sys/signal.h> constants])
AC_COMPUTE_INT([SFD_CLOEXEC], [SFD_CLOEXEC], [#include <sys/signalfd.h>])
AC_COMPUTE_INT([SIG_BLOCK], [SIG_BLOCK], [#include <sys/signal.h>])
AC_COMPUTE_INT([SIG_UNBLOCK], [SIG_UNBLOCK], [#include <sys/signal.h>])
AC_COMPUTE_INT([SIG_SETMASK], [SIG_SETMASK], [#include <sys/signal.h>])
AC_MSG_RESULT([done])

SIZEOF_STRUCT_SIGNALFD_SIGINFO="$ac_cv_sizeof_struct_signalfd_siginfo"
SIZEOF_SIGSET_T="$ac_cv_sizeof_sigset_t"
AC_SUBST([SIZEOF_STRUCT_SIGNALFD_SIGINFO])
AC_SUBST([SIZEOF_SIGSET_T])
AC_SUBST([SFD_CLOEXEC])
AC_SUBST([SIG_BLOCK])
AC_SUBST([SIG_UNBLOCK])
AC_SUBST([SIG_SETMASK])

AC_MSG_CHECKING([whether to build crash handler])
case "$host_os" in
  linux-gnu*)  build_crash_handler=yes;;
  *)           build_crash_handler=no;;
esac
AC_MSG_RESULT([$build_crash_handler])

AC_MSG_CHECKING([which mechanism to use for detecting the open file descriptors])
case "$host_os" in
  linux-gnu*) open_fdes_mechanism=proc;;
  gnu*) open_fdes_mechanism=hurd;;
  *)
    AC_MSG_WARN([not sure how to discover open file descriptors on '$host_os', assuming /proc])
    open_fdes_mechanism=proc;;
esac
AC_MSG_RESULT([$open_fdes_mechanism])

AM_CONDITIONAL([BUILD_CRASH_HANDLER], [test "x$build_crash_handler" = "xyes"])
AM_CONDITIONAL([BUILD_OPEN_FDES], [test "$open_fdes_mechanism" = "hurd"])

dnl Manual pages.
AM_MISSING_PROG([HELP2MAN], [help2man])

dnl Finish.
AC_CONFIG_FILES([Makefile po/Makefile.in
                 modules/shepherd/system.scm])

AC_OUTPUT
